package com.inexas.cu.klient.test;

import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.*;
import com.google.inject.*;
import com.inexas.cu.client.eventbus.*;
import com.inexas.cu.client.mvp.*;
import com.inexas.cu.client.test.*;
import com.inexas.cu.client.test.TestPm.*;

public class UtPresentationManager implements Source {
	public class TestModule extends AbstractModule {

		@Override
		protected void configure() {
			bind(TestPresenter.class);
		}

		@Provides
		TestView provideTestView() {
			view = createMock(TestView.class);
			return view;
		}

		@Provides
		EventBus provideEventBus() {
			eventBus = createMock(EventBus.class);
			return eventBus;
		}

	}

	@SuppressWarnings("unused")
	private TestPresenter presenter;
	private TestView view;
	private EventBus eventBus;
	private TestPm pm;

	@Before
	public void setup() {
		final Injector factory = Guice.createInjector(new TestModule());
		presenter = factory.getInstance(TestPresenter.class);
		pm = TestGWT.create(TestPm.class);
	}

	@Test
	public void agregation() {
		assertTrue(pm.getObserverCount() == 0);
		assertTrue(((ObservableImpl)pm.getProperty()).getObserverCount() == 1);
		assertTrue(((ObservableImpl)pm.getPropertyList()).getObserverCount() == 1);
		assertTrue(((ObservableImpl)pm.getTuple()).getObserverCount() == 1);
		assertTrue(((ObservableImpl)pm.getTuple().getMember()).getObserverCount() == 1);
		assertTrue(((ObservableImpl)pm.getTupleList()).getObserverCount() == 1);

		// Add an element to tupleList..
		final TupleList<TestTuple> tupleList = pm.getTupleList();
		final TestTuple added = new TestTuple("testTuple[0]");
		assertTrue(((ObservableImpl)added).getObserverCount() == 0);
		assertTrue(((ObservableImpl)added.getMember()).getObserverCount() == 0);
		tupleList.add(this, added);
		assertTrue(((ObservableImpl)added).getObserverCount() == 1);
		assertTrue(((ObservableImpl)added.getMember()).getObserverCount() == 1);

		// Remove the element we just added...
		tupleList.remove(this, added);
		assertTrue(((ObservableImpl)added).getObserverCount() == 0);
		assertTrue(((ObservableImpl)added.getMember()).getObserverCount() == 0);
	}

}
